import java.sql.*;

public class TestJDBC {
	public static void main(String[] args){
		ResultSet rs = null;
		Statement sta = null;
		Connection conn = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:lovemanai", "scott", "tiger");
			sta = conn.createStatement();
			rs = sta.executeQuery("select * from emp");
			while(rs.next()) {
				System.out.println(rs.getString("deptno"));
			}
		} catch(ClassNotFoundException e) {
			System.out.println("没有找到相应驱动");
		} catch(SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(rs != null) rs.close();
				if(sta != null) sta.close();
				if(conn != null) conn.close();
			} catch(SQLException e) {
				e.printStackTrace();
			}
			
		}
		
	}
}
